package com.jiutong.meipengdai.http.model.requests;

import com.jiutong.meipengdai.http.RetrofitHandle;
import com.jiutong.meipengdai.http.SubscribeHandler;
import com.jiutong.meipengdai.http.model.services.LoanRelaService;
import com.jiutong.meipengdai.http.subscribers.ProgressSubscriber;

import java.util.HashMap;
import java.util.Map;

import rx.Observable;
import rx.Subscriber;

/**
 * 贷款相关
 * Created by suxi on 2017/5/31.
 */

public class LoanRelaRequest extends SubscribeHandler {
    /**
     * 自动认证
     *
     * @param subscriber
     * @param fields
     */
    public void autoAuth(Subscriber subscriber, Map<String, Object> fields) {

        fields.put("method", "evalue.auto");
        fields.put("v", "2.0");

        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(LoanRelaService.class)
                .autoAuth(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 贷款记录
     *
     * @param subscriber
     * @param fields
     */
    public void loanRecord(Subscriber subscriber, Map<String, Object> fields) {

        fields.put("method", "acct.loanRecord");
        fields.put("v", "2.0");
        handleFields(fields);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(LoanRelaService.class)
                .loanRecord(fields);
        toSubscribe(observable, subscriber);
    }

    /**
     * 贷款详情页
     *
     * @param progressSubscriber
     * @param fieldsMap
     */

    public void loanDetail(ProgressSubscriber progressSubscriber, HashMap<String, Object> fieldsMap) {
        fieldsMap.put("method", "acct.loanInfo");
        handleFields(fieldsMap);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(LoanRelaService.class)
                .loanDetail(fieldsMap);
        toSubscribe(observable, progressSubscriber);
    }

    /**
     * 房产详情页
     *
     * @param progressSubscriber
     * @param fieldsMap
     */
    public void getHouseDetail(ProgressSubscriber progressSubscriber, HashMap<String, Object> fieldsMap) {
        fieldsMap.put("method", "user.house");
        fieldsMap.put("v", "2.0");
        handleFields(fieldsMap);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(LoanRelaService.class)
                .getHouseDetail(fieldsMap);
        toSubscribe(observable, progressSubscriber);
    }

    /**
     * 还款列表
     *
     * @param progressSubscriber
     * @param fieldsMap
     */
    public void repayList(ProgressSubscriber progressSubscriber, HashMap<String, Object> fieldsMap) {
        fieldsMap.put("method", "acct.repayRecord");
        handleFields(fieldsMap);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(LoanRelaService.class)
                .repayList(fieldsMap);
        toSubscribe(observable, progressSubscriber);
    }

    /**
     * 申请展期
     *
     * @param progressSubscriber
     * @param map
     */
    public void applyDay(ProgressSubscriber progressSubscriber, HashMap<String, Object> map) {
        map.put("method", "loan.applyPostpone");
        handleFields(map);
        Observable observable = RetrofitHandle.getInstance().retrofit.create(LoanRelaService.class)
                .applyDay(map);
        toSubscribe(observable, progressSubscriber);
    }
}
